package epsi.mobile.adapters;

import java.util.ArrayList;

import epsi.mobile.entities.Store;
import epsi.mobile.storelocator.R;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/*
 * This class customize the elements in the list of stores
 */
public class StoreListViewAdapter extends BaseAdapter
{
    private final Activity         activity;
    private final ArrayList<Store> storeList;

    public StoreListViewAdapter(Activity activity, ArrayList<Store> storeList)
    {
        super();
        this.activity = activity;
        this.storeList = storeList;
    }

    // Customize a view
    @Override
    public View getView(int position, View view, ViewGroup parent)
    {
        LayoutInflater inflater = activity.getLayoutInflater();
        View rowView = inflater.inflate(R.layout.storelistviewtemplate, null, true);

        TextView txtTitle = (TextView) rowView.findViewById(R.id.textView_name);
        TextView txtAdress = (TextView) rowView.findViewById(R.id.textView_adress);
        TextView txtCity = (TextView) rowView.findViewById(R.id.textView_cpcity);

        txtTitle.setText(storeList.get(position).getStoreName());
        txtAdress.setText(storeList.get(position).getAdress());
        txtCity.setText(storeList.get(position).getPostalCode() + " " + storeList.get(position).getCity());

        return rowView;
    }

    @Override
    public int getCount()
    {
        // TODO Auto-generated method stub
        return this.storeList.size();
    }

    @Override
    public Object getItem(int position)
    {
        // TODO Auto-generated method stub
        return this.storeList.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        // TODO Auto-generated method stub
        return 0;
    }

}